package com.cqndt.disaster.device.common.shrio;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.apache.shiro.subject.Subject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.cqndt.disaster.device.common.util.PrintUtil;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;

/**
 * @author lgb
 * @date 2020-8-26
 * @说明 shiro未登录反回状态码
 **/
public class LoginAuthorizationFilter extends FormAuthenticationFilter {
   
    /**
     * @param request
     * @return 这个方法是未登录需要执行的方法
     **/
    @Override
    protected boolean onAccessDenied(ServletRequest request,
    		ServletResponse response) throws Exception {
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpServletResponse httpResponse = (HttpServletResponse) response;
        Subject subject = getSubject(request, response);
        if (subject.getPrincipal() == null) {
            PrintUtil.printJson(httpRequest,httpResponse, -3,"登录超时,请重新登录");
        }
        return false;
    }
}